home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 19.8 KB | 658 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FRProxy.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWPROXY_H
- #include "FWProxy.h"
- #endif
-
- #ifndef FWPARTNG_H
- #include "FWPartng.h"
- #endif
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWPXYFRM_H
- #include "FWPxyFrm.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- // ----- Graphic Includes -----
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- ODF Foundation Includes -----
-
- #ifndef FWDEBUG_H
- #include "FWDebug.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- // ----- ODUtil Includes -----
-
- #ifndef FWORDCOL_H
- #include "FWOrdCol.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- //========================================================================================
- // Runtime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fw_embedding
- #endif
-
- FW_DEFINE_CLASS_M0(FW_MProxy)
-
- //========================================================================================
- // class FW_MProxy
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::FW_MProxy
- //----------------------------------------------------------------------------------------
-
- FW_MProxy::FW_MProxy(Environment* ev, FW_CEmbeddingPart* part, FW_CPresentation* presentation) :
- fPart(part),
- fPresentation(presentation),
- fProxyFrames(NULL),
- fClonedFrameID(kODNULLID),
- fEmbeddedFacetCount(0),
- fSelected(FALSE)
- {
- FW_ASSERT(fPart != NULL);
- FW_ASSERT(fPresentation != NULL);
-
- fProxyFrames = new FW_CPrivOrderedCollection;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::~FW_MProxy
- //----------------------------------------------------------------------------------------
-
- FW_MProxy::~FW_MProxy()
- {
- if (fProxyFrames)
- {
- Environment* ev = somGetGlobalEnvironment();
-
- FW_CProxyFrame* proxyFrame;
- while ((proxyFrame = (FW_CProxyFrame*)fProxyFrames->First()) != NULL)
- {
- FW_ASSERT(proxyFrame->GetProxy(ev) == this);
- proxyFrame->SetProxy(ev, NULL);
- PrivRemoveProxyFrame(ev, proxyFrame); // Will delete it if I am the last one to hold on it
- }
-
- delete fProxyFrames;
- fProxyFrames = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::UsedShapeChanged
- //----------------------------------------------------------------------------------------
- // The used shape of one of my embedded frame has changed
-
- void FW_MProxy::UsedShapeChanged(Environment *ev,
- FW_CEmbeddingFrame* embeddingFrame,
- ODFrame* odEmbeddedFrame)
- {
- FW_UNUSED(ev);
- FW_UNUSED(embeddingFrame);
- FW_UNUSED(odEmbeddedFrame);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::FrameShapeRequested
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_MProxy::FrameShapeRequested(Environment* ev,
- ODFrame* odEmbeddedFrame,
- ODShape* frameShape)
- {
- FW_UNUSED(odEmbeddedFrame);
-
- frameShape->Acquire(ev);
- return frameShape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::AttachEmbeddedFrames
- //----------------------------------------------------------------------------------------
-
- void FW_MProxy::AttachEmbeddedFrames(Environment *ev)
- {
- FW_CProxyProxyFrameIterator ite(this);
- for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- proxyFrame->PrivAttach(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::DetachEmbeddedFrames
- //----------------------------------------------------------------------------------------
- // At the end proxyFrames are only owned by the proxy
-
- void FW_MProxy::DetachEmbeddedFrames(Environment *ev)
- {
- FW_CProxyProxyFrameIterator ite(this);
- for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- proxyFrame->PrivDetach(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::RemoveEmbeddedFrames
- //----------------------------------------------------------------------------------------
- // At the end this proxy doesn't have any proxyframes
- // Attention: Use DetachEmbeddedFrames if you are supporting Undo
-
- void FW_MProxy::RemoveEmbeddedFrames(Environment *ev)
- {
- // ----- First detach them
- DetachEmbeddedFrames(ev);
-
- // ----- Remove all the embedded frames -----
- FW_CProxyFrame* proxyFrame ;
- while ((proxyFrame = (FW_CProxyFrame*)fProxyFrames->First()) != NULL)
- {
- long refCount = PrivRemoveProxyFrame(ev, proxyFrame);
- FW_ASSERT(refCount == 0);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::PrivRemoveProxyFrame
- //----------------------------------------------------------------------------------------
-
- long FW_MProxy::PrivRemoveProxyFrame(Environment* ev, FW_CProxyFrame* proxyFrame)
- {
- fProxyFrames->Remove(proxyFrame);
- proxyFrame->SetProxy(ev, NULL);
- return proxyFrame->Release();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::PrivAcquireProxyFrame
- //----------------------------------------------------------------------------------------
-
- FW_CProxyFrame* FW_MProxy::PrivAcquireProxyFrame(Environment* ev, ODStorageUnitID frameID) const
- {
- return FW_CProxyFrame::PrivAcquireProxyFrame(ev, fProxyFrames, frameID);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::GetEmbeddedFacetUnderMouse
- //----------------------------------------------------------------------------------------
- // 'mouse' in Frame coordinate system
-
- ODFacet* FW_MProxy::GetEmbeddedFacetUnderMouse(Environment* ev, ODFacet* embeddingFacet, const FW_CPoint& mouse) const
- {
- ODPoint odMouse = mouse;
-
- FW_CEmbeddedODFacetsIterator ite(ev, this, embeddingFacet, kODFrontToBack);
- for (ODFacet* odFacet = ite.First(ev); ite.IsNotComplete(ev); odFacet = ite.Next(ev))
- {
- if (odFacet->ContainsPoint(ev, &odMouse, NULL))
- return odFacet;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::SetSelectState
- //----------------------------------------------------------------------------------------
-
- void FW_MProxy::SetSelectState(Environment* ev, FW_Boolean state)
- {
- fSelected = state;
-
- // ----- Set the selected flag in facet -----
- FW_CProxyEmbeddedFrameIterator ite(ev, this);
- for (ODFrame* odEmbeddedFrame = ite.First(ev); ite.IsNotComplete(ev); odEmbeddedFrame = ite.Next(ev))
- {
- FW_CODFrameFacetIterator ite2(ev, odEmbeddedFrame);
- for (ODFacet* facet = ite2.First(ev); ite2.IsNotComplete(ev); facet = ite2.Next(ev))
- facet->SetSelected(ev, state);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::GetEmbeddedPart
- //----------------------------------------------------------------------------------------
-
- ODPart* FW_MProxy::GetEmbeddedPart(Environment* ev) const
- {
- // Can't be called when empty because proxys are automtically deleted
- FW_ASSERT(fProxyFrames->Count() != 0);
-
- FW_CProxyFrame* proxyFrame = (FW_CProxyFrame*)fProxyFrames->First();
-
- FW_CAcquiredODPart aqODPart = proxyFrame->GetFrame(ev)->AcquirePart(ev);
- return aqODPart;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::AcquireProxyFrame
- //----------------------------------------------------------------------------------------
- // Acquire a proxyframe knowing its embedding frame
-
- FW_CProxyFrame* FW_MProxy::AcquireProxyFrame(Environment* ev, FW_CEmbeddingFrame* embeddingFrame) const
- {
- FW_CProxyProxyFrameIterator ite(this);
- for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- if (proxyFrame->GetContainingFrame(ev) == embeddingFrame)
- {
- proxyFrame->Acquire();
- return proxyFrame;
- }
- }
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::GetEmbeddedFrame
- //----------------------------------------------------------------------------------------
- // returns the embedded frame of this proxy (embedded) frame
-
- ODFrame* FW_MProxy::GetEmbeddedFrame(Environment* ev, FW_CEmbeddingFrame* embeddingFrame) const
- {
- FW_CAcquiredProxyFrame aqProxyFrame = AcquireProxyFrame(ev, embeddingFrame);
- return ((const void*)aqProxyFrame == NULL) ? NULL : aqProxyFrame->GetFrame(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::IsEmbeddedFrame
- //----------------------------------------------------------------------------------------
- // returns true if the embeddedframe belongs to this proxy
-
- FW_Boolean FW_MProxy::IsEmbeddedFrame(Environment* ev, ODFrame* embeddedFrame) const
- {
- ODID frameID = embeddedFrame->GetID(ev);
- FW_CProxyProxyFrameIterator ite(this);
- for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- if (proxyFrame->GetFrameID(ev) == frameID)
- return TRUE;
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::Externalize
- //----------------------------------------------------------------------------------------
-
- void FW_MProxy::Externalize(Environment* ev,
- ODStorageUnitView* destinationSUView,
- FW_CCloneInfo* cloneInfo)
- {
- FW_CFrame* scopeFrame = cloneInfo->GetScopeFrame(ev);
-
- if (cloneInfo != NULL && scopeFrame != NULL)
- {
- unsigned long count = 1;
- FW_CByteArray byteArray(&count, sizeof(unsigned long));
- destinationSUView->SetValue(ev, byteArray);
-
- #ifdef FW_DEBUG
- FW_CEmbeddingFrame* scopeEmbeddingFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, scopeFrame);
- FW_ASSERT(scopeEmbeddingFrame);
- FW_CAcquiredProxyFrame aqProxyFrame = AcquireProxyFrame(ev, scopeEmbeddingFrame);
- #else
- FW_CAcquiredProxyFrame aqProxyFrame = AcquireProxyFrame(ev, (FW_CEmbeddingFrame*)scopeFrame);
- #endif
- FW_ASSERT((const void*)aqProxyFrame != NULL);
-
- FW_Boolean result = aqProxyFrame->ExternalizeProxyFrame(ev, destinationSUView, cloneInfo);
- FW_ASSERT(result = TRUE);
- }
- else
- {
- FW_CProxyFrame* proxyFrame;
- unsigned long count = 0;
-
- // Count only the proxyFrame with a containing frame persistent
- FW_CProxyProxyFrameIterator ite(this);
- for (proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- if (proxyFrame->GetContainingFrame(ev)->IsPersistent(ev))
- count++;
- }
-
- // ----- Save the count -----
- FW_CByteArray byteArray(&count, sizeof(unsigned long));
- destinationSUView->SetValue(ev, byteArray);
-
- // ----- Externalize each proxy -----
- FW_CProxyProxyFrameIterator ite2(this);
- for (proxyFrame = ite2.First(); ite2.IsNotComplete(); proxyFrame = ite2.Next())
- {
- FW_Boolean result = proxyFrame->ExternalizeProxyFrame(ev, destinationSUView, cloneInfo);
- FW_ASSERT(result = TRUE);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::PrivPostClone
- //----------------------------------------------------------------------------------------
-
- void FW_MProxy::PrivPostClone(Environment* ev, FW_CFrame* scopeFrame)
- {
- if (fClonedFrameID == kODNULLID)
- return;
-
- ODDraft* myDraft = GetPart(ev)->GetStorageUnit(ev)->GetDraft(ev);
-
- // ----- Get the new frame from my draft -----
- FW_CAcquiredODFrame aqODEmbeddedFrame = myDraft->AcquireFrame(ev, fClonedFrameID);
- FW_ASSERT(aqODEmbeddedFrame != NULL);
-
- // ----- Set the containing frame
- aqODEmbeddedFrame->SetContainingFrame(ev, scopeFrame->GetODFrame(ev));
-
- // ----- Now we can embed it -----
- FW_CAcquiredODShape aqFrameShape = aqODEmbeddedFrame->AcquireFrameShape(ev, NULL);
- FW_CAcquiredODPart aqODPart = aqODEmbeddedFrame->AcquirePart(ev);
- fPresentation->Embed(ev,
- aqODPart,
- aqODEmbeddedFrame,
- this,
- aqFrameShape,
- aqODEmbeddedFrame->GetViewType(ev),
- aqODEmbeddedFrame->GetPresentation(ev),
- aqODEmbeddedFrame->GetFrameGroup(ev),
- aqODEmbeddedFrame->IsSubframe(ev));
-
- // ----- Cloning done -----
- fClonedFrameID = kODNULLID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::Internalize
- //----------------------------------------------------------------------------------------
-
- void FW_MProxy::Internalize(Environment* ev,
- ODStorageUnitView* sourceSUView,
- FW_CCloneInfo *cloneInfo)
- {
- if (cloneInfo != NULL)
- {
- FW_ASSERT(cloneInfo->GetScopeFrame(ev));
-
- if (cloneInfo->fClonedProxyList == NULL)
- cloneInfo->fClonedProxyList = new FW_CPrivOrderedCollection;
-
- cloneInfo->fClonedProxyList->AddLast(this);
-
- // ----- Read the number of embedded frames -----
- unsigned long count;
- FW_CByteArray byteArray;
- sourceSUView->GetValue(ev, sizeof(unsigned long), byteArray);
- byteArray.CopyBuffer(&count, sizeof(unsigned long));
-
- FW_ASSERT(count == 1); // if clone we should have only one embedded frame
-
- ODStorageUnitRef aSURef;
- sourceSUView->GetValue(ev, sizeof(ODStorageUnitRef), byteArray);
- byteArray.CopyBuffer(&aSURef, sizeof(ODStorageUnitRef));
-
- FW_ASSERT(sourceSUView->IsValidStorageUnitRef(ev, aSURef));
-
- ODStorageUnitID fromFrameID = sourceSUView->GetIDFromStorageUnitRef(ev, aSURef);
- fClonedFrameID = cloneInfo->Clone(ev, fromFrameID, 0, 0);
- }
- else
- {
- unsigned long count;
-
- FW_CByteArray byteArray;
- sourceSUView->GetValue(ev, sizeof(unsigned long), byteArray);
- byteArray.CopyBuffer(&count, sizeof(unsigned long));
-
- for (unsigned long i = 0; i<count; i++)
- {
- ODStorageUnitRef aSURef;
- sourceSUView->GetValue(ev, sizeof(ODStorageUnitRef), byteArray);
- byteArray.CopyBuffer(&aSURef, sizeof(ODStorageUnitRef));
-
- if (sourceSUView->IsValidStorageUnitRef(ev, aSURef))
- {
- ODStorageUnitID frameID = sourceSUView->GetIDFromStorageUnitRef(ev, aSURef);
-
- // ----- look first if the part has a proxyframe with this Id
- FW_CAcquiredProxyFrame aqProxyFrame = fPart->PrivAcquireProxyFrame(ev, frameID);
-
- // ----- could not find it. Just create one
- if ((const void*)aqProxyFrame == NULL)
- aqProxyFrame = new FW_CProxyFrame(ev, fPart, this, frameID);
- else
- {
- aqProxyFrame->SetProxy(ev, this);
- this->PrivAddProxyFrame(ev, aqProxyFrame);
- }
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::SetEmbeddedFramesViewType
- //----------------------------------------------------------------------------------------
- // ATTENTION: I am forcing the embedded frame to be in memory
-
- void FW_MProxy::SetEmbeddedFramesViewType(Environment* ev, ODTypeToken viewType)
- {
- FW_CProxyProxyFrameIterator ite(this);
- for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- proxyFrame->GetFrame(ev)->SetViewType(ev, viewType);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::ChangeExternalTransforms
- //----------------------------------------------------------------------------------------
-
- void FW_MProxy::ChangeExternalTransforms(Environment* ev, FW_CFixed x, FW_CFixed y)
- {
- if (fEmbeddedFacetCount != 0)
- {
- FW_CAcquiredODTransform transform = ::FW_NewODTransform(ev, FW_CPoint(x, y));
- ChangeExternalTransforms(ev, transform);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::ChangeExternalTransforms
- //----------------------------------------------------------------------------------------
-
- void FW_MProxy::ChangeExternalTransforms(Environment* ev, ODTransform* transform)
- {
- FW_ASSERT(transform);
-
- if (fEmbeddedFacetCount == 0)
- return;
-
- transform->Acquire(ev);
- FW_CAcquiredODTransform aqTransform(transform);
-
- FW_CProxyProxyFrameIterator ite(this);
- for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- if (proxyFrame->IsFrameInMemory(ev))
- {
- FW_CAcquiredODTransform aqCopy;
-
- if (transform == NULL)
- aqCopy = transform = aqTransform->Copy(ev);
-
- FW_CODFrameFacetIterator ite(ev, proxyFrame->GetFrame(ev));
- for (ODFacet* odFacet = ite.First(ev); ite.IsNotComplete(ev); odFacet = ite.Next(ev))
- {
- odFacet->ChangeGeometry(ev, NULL, transform, NULL);
- }
-
- transform = NULL;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::ChangeFrameShapes
- //----------------------------------------------------------------------------------------
-
- void FW_MProxy::ChangeFrameShapes(Environment* ev, FW_CFixed width, FW_CFixed height)
- {
- FW_CProxyProxyFrameIterator ite(this);
- for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- if (proxyFrame->IsFrameInMemory(ev))
- {
- FW_CAcquiredODShape newFrameShape = ::FW_NewODShape(ev, FW_CRect(FW_kZeroPoint, width, height));
- proxyFrame->GetFrame(ev)->ChangeFrameShape(ev, newFrameShape, NULL);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::ChangeFrameShapes
- //----------------------------------------------------------------------------------------
-
- void FW_MProxy::ChangeFrameShapes(Environment* ev, ODShape* newShape)
- {
- FW_ASSERT(newShape != NULL);
-
- FW_CProxyProxyFrameIterator ite(this);
- for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- if (proxyFrame->IsFrameInMemory(ev))
- {
- FW_CAcquiredODShape aqShape(newShape->Copy(ev));
- proxyFrame->GetFrame(ev)->ChangeFrameShape(ev, aqShape, NULL);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::PrivAddProxyFrame
- //----------------------------------------------------------------------------------------
-
- void FW_MProxy::PrivAddProxyFrame(Environment* ev, FW_CProxyFrame* proxyFrame)
- {
- #ifdef FW_DEBUG
- FW_CProxyProxyFrameIterator ite(this);
- for (FW_CProxyFrame* pf = ite.First(); ite.IsNotComplete(); pf = ite.Next())
- {
- if (pf == proxyFrame)
- FW_DEBUG_MESSAGE("FW_MProxy::PrivAddProxyFrame ProxyFrame already attached");
- }
- #endif
-
- FW_ASSERT(proxyFrame->GetProxy(ev) == this);
-
- fProxyFrames->AddLast(proxyFrame);
- proxyFrame->Acquire();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MProxy::AdjustBorderShape
- //----------------------------------------------------------------------------------------
- // Shape is content coordinate and already intersected with the content shape
-
- void FW_MProxy::AdjustBorderShape(Environment* ev,
- FW_CEmbeddingFrame* embeddingFrame,
- ODFacet* embeddedFacet,
- ODShape *shape)
- {
- }
-